package com.thon.dao.user.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.thon.dao.user.PresentDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.user.Present;

/**
 * @file PresentDaoImpl.java
 * @author wang
 * @date 2014年6月24日
 * @description TODO
 */
@Repository

public class PresentDaoImpl extends AbstractDao<Present> implements PresentDao {
	
	public PresentDaoImpl() {
		super(Present.class);
	}

	@Override
	public Page<Present> findAllByPhone(Page<Present> page, String loginName) {
		
		String queryString = "FROM Present p WHERE p.toPhone = ? ORDER BY support.createdDate DESC";
		return findPage(page, queryString, loginName); 
	}

	@Override
	public Page<Present> findPresentByStatus(Page<Present> page, String loginName, int status) {

		String queryString = "FROM Present p WHERE p.toPhone = ? "
				+ "AND p.status = ?";
		return findPage(page, queryString, loginName, status);
	}

	@Override
	public Long countPresent(String loginName) {
		String queryString = "SELECT count(*) FROM Present WHERE toPhone = ? AND status = ?";
		return count(queryString, loginName,Present.STATUS_UNREAD);
	}

	@Override
	public List<Present> listPresentByPhone(String loginName) {
		String queryString = "FROM Present p WHERE p.toPhone = ? ORDER BY support.createdDate DESC";
		return findList(queryString, null, loginName);
	}
}
